<?php
//echo 'Class SPHP';
class SPHP
{
	public static function get_char_from_last($str, $num)
	{
		return substr($str, -$num);
	}
	public static function string_replace($text, $str, $with)
	{
		return str_replace($str, $with, $text);
	}
	
	public static function is_ie()
	{
		if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public static function get_the_ip_address() 
	{    
		if (!empty($_SERVER['HTTP_CLIENT_IP']))
		{      
			 $ip=$_SERVER['HTTP_CLIENT_IP'];    
		}     
		elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
		{    
			 $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];  
		}   
		else   
		{      
			 $ip=$_SERVER['REMOTE_ADDR'];    
		}   
		return $ip; 
	}
	
	public static function convert_html($str, $to_spec = true)
	{
		$result = '';
		if($to_spec)
		{
			$result = htmlspecialchars($str);
		}
		else
		{
			$result = htmlspecialchars_decode($str);
		}
		return $result;
	}
	
	public static function remove_cookies()
	{
		if (isset($_SERVER['HTTP_COOKIE']))
		{
			$cookies = explode(';', $_SERVER['HTTP_COOKIE']);
			foreach($cookies as $cookie)
			{
				$parts = explode('=', $cookie);
				$name = trim($parts[0]);
				setcookie($name, '', time()-1000);
				setcookie($name, '', time()-1000, '/');
			}
		}
	}
	public static function get_first_char($string)
	{
		return $string[0];
	}
	public static function remove_first_char($string)
	{
		$str = substr($string, 1);
		return $str;
	}
	public static function string_uppercase($string)
	{
		return strtoupper($string);
	}
	public static function first_char_uppercase($string)
	{
		$first = self::get_first_char($string);
		$string = self::remove_first_char($string);
		$string = self::string_uppercase($first).$string;
		return $string;
	}
	
	public static function first_char_to_uppercase($string)
	{
		return self::first_char_uppercase($string);
	}
	public static function is_string_contain($string, $text)
	{
		if (strpos($string, $text) !== false)
		{
			return true;
		}
		return false;
	}
	public static function add_to_array(&$arr, $value)
	{
		array_push($arr, $value);
	}
	public static function get_base_uri()
	{
		$url = sprintf("%s://%s", isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', $_SERVER['HTTP_HOST']);
		return $url;
	}
	
	public static function get_current_uri()
	{
		$url = sprintf("%s://%s%s", isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', $_SERVER['HTTP_HOST'], $_SERVER["REQUEST_URI"]);
		return $url;
	}
}
?>